package com.kkd.kkdapp.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.kkd.kkdapp.http.entity.AllConfig;
import com.kkd.kkdapp.http.entity.FindData;
import com.kkd.kkdapp.http.entity.FindDataActiveItem;
import com.kkd.kkdapp.http.entity.Home;
import com.kkd.kkdapp.http.entity.HomeData;
import com.kkd.kkdapp.http.entity.HomePageData;
import com.kkd.kkdapp.http.entity.InviteFriendShare;
import com.kkd.kkdapp.http.entity.TiYanActivity;

public class PreferenceUtils {

	// public boolean popflag = true;
	public boolean confirmPatternflag = true;
	public boolean setPatternflag = true;
	public boolean setButtonflag = true;
	public boolean isMustRight = true;

	private static PreferenceUtils instance;

	private PreferenceUtils() {
	}

	public static PreferenceUtils getInstance() {
		if (instance == null) {
			instance = new PreferenceUtils();
		}
		return instance;
	}

	public static SharedPreferences getPreferences(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context);
	}

	public static String getString(String key, String defaultValue,
			Context context) {
		return getPreferences(context).getString(key, defaultValue);
	}

	public static Set<String> getStringSet(String key,
			Set<String> defaultValue, Context context) {
		return getPreferences(context).getStringSet(key, defaultValue);
	}

	public static int getInt(String key, int defaultValue, Context context) {
		return getPreferences(context).getInt(key, defaultValue);
	}

	public static long getLong(String key, long defaultValue, Context context) {
		return getPreferences(context).getLong(key, defaultValue);
	}

	public static float getFloat(String key, float defaultValue, Context context) {
		return getPreferences(context).getFloat(key, defaultValue);
	}

	public static boolean getBoolean(String key, boolean defaultValue,
			Context context) {
		return getPreferences(context).getBoolean(key, defaultValue);
	}

	public static SharedPreferences.Editor getEditor(Context context) {
		return getPreferences(context).edit();
	}

	public static void putString(String key, String value, Context context) {
		getEditor(context).putString(key, value).apply();
	}

	public static void putStringSet(String key, Set<String> value,
			Context context) {
		getEditor(context).putStringSet(key, value).apply();
	}

	public static void putInt(String key, int value, Context context) {
		getEditor(context).putInt(key, value).apply();
	}

	public static void putLong(String key, long value, Context context) {
		getEditor(context).putLong(key, value).apply();
	}

	public static void putFloat(String key, float value, Context context) {
		getEditor(context).putFloat(key, value).apply();
	}

	public static void putBoolean(String key, boolean value, Context context) {
		getEditor(context).putBoolean(key, value).apply();
	}

	public static void remove(String key, Context context) {
		getEditor(context).remove(key).apply();
	}

	public static void clear(Context context) {
		getEditor(context).clear().apply();
	}

	/**
	 * 登陆标识赋值
	 * 
	 * @param context
	 * @param code
	 */
	public void setLogin(Context context, int code) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"loginMessage", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("code", code);
		editor.commit();
	}

	/**
	 * 获取登陆标识
	 * 
	 * @return
	 */
	public static int getLogin(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"loginMessage", Context.MODE_PRIVATE);
		int code = sharedPreferences.getInt("code", -1);
		return code;
	}

	/**
	 * 实名认证标识赋值
	 * 
	 * @param context
	 * @param isRealNameAuth
	 */
	public void setAutonym(Context context, int isRealNameAuth) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Autonym", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("isRealNameAuth", isRealNameAuth);
		editor.commit();

	}

	/**
	 * 获取账户页 ，交易明细搬家了，显示次数
	 * 
	 * @return
	 */
	public int getJiaoyiShowTime(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"JiaoyiShowTime", Context.MODE_PRIVATE);
		int time = sharedPreferences.getInt("JiaoyiShowTime", 0);
		return time;
	}

	public int setJiaoyiShowTime(Context context, int time) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"JiaoyiShowTime", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("JiaoyiShowTime", time);
		editor.commit();
		return time;
	}

	/**
	 * 获取实名认证标识
	 * 
	 * @return
	 */
	public int getAutonym(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Autonym", Context.MODE_PRIVATE);
		int isRealNameAuth = sharedPreferences.getInt("isRealNameAuth", -1);
		return isRealNameAuth;
	}

	/**
	 * 银行卡绑定标识赋值
	 * 
	 * @param context
	 * @param isBoundBankCard
	 */
	public void setBoundBankCard(Context context, int isBoundBankCard) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"BoundBankCard", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("isBoundBankCard", isBoundBankCard);
		editor.commit();

	}

	/**
	 * 获取银行卡绑定标识
	 * 
	 * @return
	 */
	public int getBoundBankCard(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"BoundBankCard", Context.MODE_PRIVATE);
		int isBoundBankCard = sharedPreferences.getInt("isBoundBankCard", -1);
		return isBoundBankCard;
	}

	/**
	 * 开户标识赋值
	 * 
	 * @param context
	 * @param isOpenAccount
	 */
	public void setOpenAccount(Context context, int isOpenAccount) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OpenAccount", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("isOpenAccount", isOpenAccount);
		editor.commit();

	}

	/**
	 * 获取开户标识
	 * 
	 * @return
	 */
	public int getOpenAccount(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OpenAccount", Context.MODE_PRIVATE);
		int isOpenAccount = sharedPreferences.getInt("isOpenAccount", -1);
		return isOpenAccount;
	}

	/**
	 * 手机令牌和客户ID赋值
	 * 
	 * @param context
	 * @param token
	 * @param customerId
	 */
	public void setcustomerId(Context context, String token, String customerId) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"userid", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("token", token);
		editor.putString("customerId", customerId);
		editor.commit();

	}

	/**
	 * 获取手机令牌和客户ID
	 * 
	 * @return
	 */
	public String getcustomerId(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"userid", Context.MODE_PRIVATE);
		String token = sharedPreferences.getString("token", "");
		String customerId = sharedPreferences.getString("customerId", "");
		return token + "&" + customerId;
	}

	/**
	 * 保存手机号
	 * 
	 * @param context
	 * @param phone
	 */
	public void setPhone(Context context, String phone) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Phone", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("phone", phone);
		editor.commit();
	}

	/**
	 * 获取手机号
	 * 
	 * @return
	 */
	public String getPhone(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Phone", Context.MODE_PRIVATE);
		String phone = sharedPreferences.getString("phone", "");
		return phone;
	}

	/**
	 * 保持真实姓名和身份证号
	 * 
	 * @param context
	 * @param idCard
	 * @param realName
	 */
	public void setIdCardAndRealName(Context context, String idCard,
			String realName) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"IdCardAndRealName", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("idCard", idCard);
		editor.putString("realName", realName);
		editor.commit();

	}

	/**
	 * 获取真实姓名和身份证号
	 * 
	 * @param context
	 * @return
	 */
	public String getIdCardAndRealName(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"IdCardAndRealName", Context.MODE_PRIVATE);
		String idCard = sharedPreferences.getString("idCard", "");
		String realName = sharedPreferences.getString("realName", "");
		if ("".equals(idCard) || "".equals("realName")) {
			return null;
		} else {
			return idCard + "&" + realName;
		}

	}

	/**
	 * 赋值签到状态
	 * 
	 * @param context
	 * @param idCard
	 * @param realName
	 */
	public void setSignInFlag(Context context, int signInFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SignInFlag", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("signInFlag", signInFlag);
		editor.commit();

	}

	/**
	 * 获取签到状态
	 * 
	 * @param context
	 * @param idCard
	 * @param realName
	 */
	public int getSignInFlag(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SignInFlag", Context.MODE_PRIVATE);
		int signInFlag = sharedPreferences.getInt("signInFlag", -1);
		return signInFlag;

	}

	/**
	 * 记住登录手机号
	 */

	public void setLoginPhone(Context context, String loginphone) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"RegisterPhone", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("loginphone", loginphone);
		editor.commit();
	}

	/**
	 * 获取登录手机号
	 */
	public String getLoginPhone(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"RegisterPhone", Context.MODE_PRIVATE);
		String loginphone = sharedPreferences.getString("loginphone", "");
		return loginphone;
	}

	/**
	 * 保存提现密码是否设置状态码
	 */
	public void setWithdrawPassWord(Context context, int statusCode) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"WithdrawPassWord", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("statusCode", statusCode);
		editor.commit();
	}

	/**
	 * 获取提现密码状态码
	 */
	public int getWithdrawPassWord(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"WithdrawPassWord", Context.MODE_PRIVATE);
		int statusCode = sharedPreferences.getInt("statusCode", -1);
		return statusCode;
	}

	/**
	 * 保存二维码
	 */
	public void setTwoDimension(Context context, String friendShareUrl) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"TwoDimension", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("friendShareUrl", friendShareUrl);
		editor.commit();
	}

	/**
	 * 获取二维码
	 */
	public String getTwoDimension(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"TwoDimension", Context.MODE_PRIVATE);
		String friendShareUrl = sharedPreferences.getString("friendShareUrl",
				"");
		return friendShareUrl;
	}

	/**
	 * 保存二维码
	 */
	public void setInviteFriendUrl(Context context, String inviteFriendUrl) {
		if (TextUtils.isEmpty(inviteFriendUrl))
			return;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Qrcode", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("inviteFriendUrl", inviteFriendUrl);
		editor.commit();
	}

	/**
	 * 获取二维码
	 */
	public String getInviteFriendUrl(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Qrcode", Context.MODE_PRIVATE);
		String inviteFriendUrl = sharedPreferences.getString("inviteFriendUrl",
				"");
		return inviteFriendUrl;
	}

	/**
	 * 保存邀请好友相关信息
	 */
	public void setInviteFriend(Context context, InviteFriendShare inviteFriend) {
		if (inviteFriend == null)
			return;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"inviteFriend", Context.MODE_PRIVATE);

		Gson gson = new Gson();
		Editor editor = sharedPreferences.edit();
		editor.putString("inviteFriend", gson.toJson(inviteFriend));
		editor.commit();
	}

	/**
	 * 获取邀请好友相关信息
	 */
	public InviteFriendShare getInviteFriend(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"inviteFriend", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("inviteFriend", "");
		if (TextUtils.isEmpty(json)) {
			return null;
		} else {
			Gson gson = new Gson();
			InviteFriendShare data = gson.fromJson(json,
					InviteFriendShare.class);
			return data;
		}
	}

	/**
	 * 保存手势密码4次输入错误跳转到登录界面，登录界面返回状态
	 * 
	 * @param context
	 * @param upflag
	 */
	public void setPatternLogin(Context context, boolean loginflag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"PatternLogin", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("loginflag", loginflag);
		editor.commit();
	}

	/**
	 * 获取手势密码4次输入错误跳转到登录界面，登录界面返回状态
	 * 
	 * @param context
	 */
	public boolean getPatternLogin(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"PatternLogin", Context.MODE_PRIVATE);
		boolean upflag = sharedPreferences.getBoolean("loginflag", false);
		return upflag;
	}

	/**
	 * 保存系统消息已读
	 * 
	 * @param context
	 * @param createTime
	 */
	public void setAllreaded(Context context, long createTime) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"CreateTime", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putLong("createTime", createTime);
		editor.commit();
	}

	/**
	 * 获取系统消息已读
	 */
	public long getAllreaded(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"CreateTime", Context.MODE_PRIVATE);
		long createTime = sharedPreferences.getLong("createTime", 0);
		return createTime;
	}

	/**
	 * 保存系统消息红点是否可见状态
	 * 
	 * @param context
	 * @param createTime
	 */
	public void setSystemInformation(Context context, boolean inflag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SystemInformation", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("inflag", inflag);
		editor.commit();
	}

	/**
	 * 获取系统消息红点是否可见状态
	 * 
	 * @param context
	 * @param createTime
	 */
	public boolean getSystemInformation(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SystemInformation", Context.MODE_PRIVATE);
		boolean inflag = sharedPreferences.getBoolean("inflag", false);
		return inflag;
	}

	/**
	 * 保存头像路径
	 * 
	 */
	public void setHeadUrl(Context context, String headurl) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"HeadUrl", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("headurl", headurl);
		editor.commit();
	}

	/**
	 * 获取头像路径
	 * 
	 */
	public String getHeadUrl(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"HeadUrl", Context.MODE_PRIVATE);
		String headurl = sharedPreferences.getString("headurl", "");
		return headurl;
	}

	/**
	 * 保存首页昨日收益
	 * 
	 */
	public void setEarnings(Context context, String responseString) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Earnings", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("responseString", responseString);
		editor.commit();
	}

	/**
	 * 获取首页昨日收益
	 * 
	 */
	public String getEarnings(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Earnings", Context.MODE_PRIVATE);
		String responseString = sharedPreferences.getString("responseString",
				"");
		return responseString;
	}

	/**
	 * 
	 * 手势密码
	 * 
	 */
	public void setGesturePW(Context context, String gesturePassword) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"GesturePassword", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("gesturePassword", gesturePassword);
		editor.commit();
	}

	/**
	 * 
	 * 获取手势密码
	 * 
	 */
	public String getGesturePW(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"GesturePassword", Context.MODE_PRIVATE);
		String gesturePassword = sharedPreferences.getString("gesturePassword",
				"");
		return gesturePassword;
	}

	/**
	 * 
	 * 存入新浪UID到本地
	 * 
	 */
	public void setSinaUid(Context context, String sinaUid) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SinaUid", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("sinaUid", sinaUid);
		editor.commit();
	}

	/**
	 * 
	 * 获取本地新浪UID
	 * 
	 */
	public String getSinaUid(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SinaUid", Context.MODE_PRIVATE);
		String sinaUid = sharedPreferences.getString("sinaUid", "");
		return sinaUid;
	}

	/**
	 * 
	 * 存入昵称到本地
	 * 
	 */
	public void setNickname(Context context, String nickname) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Nickname", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("nickname", nickname);
		editor.commit();
	}

	/**
	 * 
	 * 获取本地昵称
	 * 
	 */
	public String getNickname(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Nickname", Context.MODE_PRIVATE);
		String nickname = sharedPreferences.getString("nickname", "");
		return nickname;
	}

	/***
	 * 
	 * 保存H5页面分享入口
	 * 
	 **/
	public void setH5Entrance(Context context, String entrance) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"H5Entrance", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("entrance", entrance);
		editor.commit();
	}

	/***
	 * 
	 * 获取H5页面分享入口
	 * 
	 ***/
	public String getH5Entrance(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"H5Entrance", Context.MODE_PRIVATE);
		String entrance = sharedPreferences.getString("entrance", "");
		return entrance;
	}

	/***
	 * 
	 * 保存H5页面分享参数
	 * 
	 **/
	public void setH5Parameter(Context context, String inviteFriendUrl,
			String title, String content, String logo) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"H5Parameter", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("inviteFriendUrl", inviteFriendUrl);
		editor.putString("title", title);
		editor.putString("content", content);
		editor.putString("logo", logo);
		editor.commit();
	}

	/***
	 * 
	 * 获取H5页面分享参数
	 * 
	 ***/
	public String getH5Parameter(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"H5Parameter", Context.MODE_PRIVATE);
		String inviteFriendUrl = sharedPreferences.getString("inviteFriendUrl",
				"");
		String title = sharedPreferences.getString("title", "");
		String content = sharedPreferences.getString("content", "");
		String logo = sharedPreferences.getString("logo", "");
		return inviteFriendUrl + "&" + title + "&" + content + "&" + logo;
	}

	public void clearSharePrefernces(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"H5Parameter", Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
	}

	/**********
	 * 保持银行卡号
	 **********/
	public void setCardNo(Context context, String cardNo) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"CardNo", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("cardNo", cardNo);
		editor.commit();
	}

	/**********
	 * 获取银行卡号
	 **********/
	public String getCardNo(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"CardNo", Context.MODE_PRIVATE);
		String cardNo = sharedPreferences.getString("cardNo", "");
		return cardNo;
	}

	/**
	 * 清空状态
	 * 
	 * @param context
	 */
	public void clearSharedPreferences(Context context) {
		SharedPreferences sharedPreferences;
		sharedPreferences = context.getSharedPreferences("WithdrawPassWord",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("loginMessage",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("Autonym",
				Context.MODE_PRIVATE);
		sharedPreferences = context.getSharedPreferences("SignInFlag",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("BoundBankCard",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("userid",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("IdCardAndRealName",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("CarID",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		// sharedPreferences = context.getSharedPreferences("home_data",
		// Context.MODE_PRIVATE);
		// sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("WithdrawPassWord",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("myproperty",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("iSToken",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("UpdatePattern",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("PatternLogin",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("HeadUrl",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("Earnings",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("GesturePassword",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("SinaUid",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("H5Entrance",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
		sharedPreferences = context.getSharedPreferences("CardNo",
				Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
	}

	/**
	 * 记录欢迎界面有无
	 * 
	 * @param wcflag
	 */
	public void welcomeBoolean(Context context, boolean wcflag) {
		SharedPreferences shared = context.getSharedPreferences(
				"welcomeBoolean", Context.MODE_PRIVATE);
		Editor editor = shared.edit();
		editor.putBoolean("flag", wcflag);
		editor.commit();
	}

	public boolean getwelcomeBoolean(Context context) {
		SharedPreferences shared = context.getSharedPreferences(
				"welcomeBoolean", Context.MODE_PRIVATE);

		return shared.getBoolean("flag", false);
	}

	/**
	 * 
	 * 账户向导第一次安装显示
	 */
	public void setGuide(Context context, boolean guidFlag) {
		SharedPreferences shared = context.getSharedPreferences("Guide",
				Context.MODE_PRIVATE);
		Editor editor = shared.edit();
		editor.putBoolean("guidFlag", guidFlag);
		editor.commit();
	}

	public boolean getGuide(Context context) {
		SharedPreferences shared = context.getSharedPreferences("Guide",
				Context.MODE_PRIVATE);
		return shared.getBoolean("guidFlag", false);
	}

	public void setHomeData(Context context, String json) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"home_data", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("homeData", json);
		editor.commit();
	}

	public void updateHomeOtherData(Context context, TiYanActivity other) {
		try {
			Gson gson = new Gson();
			SharedPreferences sharedPreferences = context.getSharedPreferences(
					"home_data", Context.MODE_PRIVATE);
			String cache = sharedPreferences.getString("homeData", "");
			Home home = null;
			if (!TextUtils.isEmpty(cache)) {

				home = gson.fromJson(cache, Home.class);

			} else {
				home = new Home();
				home.setData(new HomeData());
			}
			if (home != null) {
				home.getData().setOther(other);
				Editor editor = sharedPreferences.edit();
				editor.putString("homeData", gson.toJson(home));
				editor.commit();
			}
		} catch (Exception e) {
			// TODO: 出问题就算了
			e.printStackTrace();
		}

	}

	public int getKkxfStatus(Context context) {
		try {
			String cache = getHomeData(context);
			if (!TextUtils.isEmpty(cache)) {
				Gson gson = new Gson();
				Home home = gson.fromJson(cache, Home.class);
				return home.getData().getKkxfInfo().getStatus();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}

	public String getKkxfExt(Context context) {
		try {
			String cache = getHomeData(context);
			if (!TextUtils.isEmpty(cache)) {
				Gson gson = new Gson();
				Home home = gson.fromJson(cache, Home.class);
				return home.getData().getKkxfInfo().getExt();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "暂无快快享福特权";
	}

	public String getHomeData(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"home_data", Context.MODE_PRIVATE);
		String cardId = sharedPreferences.getString("homeData", "");
		return cardId;
	}

	public HomeData getHomeData2(Context context) {
		Gson gson = new Gson();
		HomeData mHomeData = null;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"home_data", Context.MODE_PRIVATE);
		String cache = sharedPreferences.getString("homeData", "");
		if (!TextUtils.isEmpty(cache)) {

			Home home = gson.fromJson(cache, Home.class);
			mHomeData = home.getData();
		}
		return mHomeData;
	}

	public boolean getIsShowMyproperty(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"IsShowMyproperty", Context.MODE_PRIVATE);
		boolean isShow = sharedPreferences.getBoolean("IsShowMyproperty", true);
		return isShow;
	}

	public void setIsShowMyproperty(Context context, boolean isShow) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"IsShowMyproperty", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("IsShowMyproperty", isShow);
		editor.commit();
	}

	public String getMyproperty(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"myproperty", Context.MODE_PRIVATE);
		String myproperty = sharedPreferences.getString("myproperty", "");
		return myproperty;
	}

	public void setMyproperty(Context context, String json) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"myproperty", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("myproperty", json);
		editor.commit();
	}

	public void setEveryDay(Context context, String responseString) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"EveryDay", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("responseString", responseString);
		editor.commit();
	}

	public String getEveryDay(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"EveryDay", Context.MODE_PRIVATE);
		String responseString = sharedPreferences.getString("responseString",
				"");
		return responseString;
	}

	public void setSinDate(String date, Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SinDate", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString("date", date);
		editor.commit();
	}

	public String getSinDate(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"SinDate", Context.MODE_PRIVATE);
		String date = sharedPreferences.getString("date", "");
		return date;
	}

	public void eliminateOneUpdate(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneUpdate", Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
	}

	/**
	 * 控制账户红点显示与不显示
	 * 
	 * @param context
	 * @return
	 */
	public void setDot(Context context, boolean dotflag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Dotflag", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("dotflag", dotflag);
		editor.commit();
	}

	public boolean getDot(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Dotflag", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("dotflag", false);
	}

	/**
	 * 手势密码上方小方格，记住设置手势密码第一次的手势
	 * 
	 */
	public void setPattern(Context context, boolean patternflag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Pattern", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("patternflag", patternflag);
		editor.commit();
	}

	/**
	 * 
	 * @param context
	 * @return
	 */
	public boolean getPattern(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"Pattern", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("patternflag", false);
	}

	/**
	 * 首页第一次进入显示提示框
	 */
	public void setShowHomePopupwindow(Context context, boolean homeflag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"ShowHomePopupwindow", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("homeflag", homeflag);
		editor.commit();
	}

	public boolean getShowHomePopupwindow(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"ShowHomePopupwindow", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("homeflag", false);
	}

	/**
	 * app第一次启动首页第一次进入显示小圆点和new图标
	 */
	public void setNewCoin(Context context, boolean newCoinFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"newCoin", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("newCoinFlag", newCoinFlag);
		editor.commit();
	}

	public boolean getNewCoin(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"newCoin", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("newCoinFlag", true);
	}

	/**
	 * 签到提醒
	 */
	public void setSignInReminder(Context context, boolean singInReminder) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"singInReminder", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("singInReminder", singInReminder);
		editor.commit();
	}

	/**
	 * 过去签到提醒
	 */
	public boolean getSignInReminder(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"singInReminder", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("singInReminder", true);
	}

	/**
	 * setHomePageData:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param homeActivity
	 * @param data
	 */
	public void setHomePageData(Context context, HomePageData data) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"HomePageData", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		Gson gson = new Gson();
		editor.putString("HomePageData", gson.toJson(data));
		editor.commit();

	}

	public HomePageData getHomePageData(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"HomePageData", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("HomePageData", "");
		if (TextUtils.isEmpty(json)) {
			return null;
		} else {
			Gson gson = new Gson();
			HomePageData data = gson.fromJson(json, HomePageData.class);
			return data;
		}

	}

	/**
	 * setHomePageData:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param homeActivity
	 * @param data
	 */
	public void setAllConfigData(Context context, AllConfig data) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"AllConfig", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		Gson gson = new Gson();
		editor.putString("AllConfig", gson.toJson(data));
		editor.commit();

	}

	public AllConfig getAllConfigData(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"AllConfig", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("AllConfig", "");
		if (TextUtils.isEmpty(json)) {
			return null;
		} else {
			Gson gson = new Gson();
			AllConfig data = gson.fromJson(json, AllConfig.class);
			return data;
		}

	}

	/***
	 * 添加登录成功以后就不弹拆红包窗口
	 */
	@SuppressLint("CommitPrefEdits")
	public void setLoginSuccess(Context context, boolean loging) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"LogingRed", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("loging", loging);
		editor.commit();
	}

	/***
	 * 获取登录成功以后就不弹拆红包窗口
	 */
	public boolean getLoginSuccess(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"LogingRed", Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean("loging", false);
	}

	/**
	 * getFindActs:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @return
	 */
	public int getFindActsUnRead(Context context) {
		HashMap<String, String> map;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"FindActs", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("FindActs", "");
		Gson gson = new Gson();
		int count = 0;
		if (!TextUtils.isEmpty(json)) {
			map = gson.fromJson(json, new TypeToken<HashMap<String, String>>() {
			}.getType());
			if (map != null)
				for (String key : map.keySet()) {
					if (map.get(key).equals("0")) {
						count++;
					}
				}
		}
		return count;
	}

	/**
	 * updateFindActs:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param activities
	 */
	public void updateFindActs(Context context, List<FindDataActiveItem> data) {
		HashMap<String, String> map;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"FindActs", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("FindActs", "");
		Gson gson = new Gson();
		if (TextUtils.isEmpty(json)) {
			map = new HashMap<String, String>();
		} else {

			map = gson.fromJson(json, new TypeToken<HashMap<String, String>>() {
			}.getType());
		}
		for (FindDataActiveItem i : data) {
			if (!map.containsKey(i.getUrl())) {
				map.put(i.getUrl(), "0");
			}
		}
		Editor editor = sharedPreferences.edit();
		editor.putString("FindActs", gson.toJson(map));
		editor.commit();

	}

	/**
	 * setFindActsAllRead:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param mCurActivity
	 */
	public void setFindActsAllRead(Context context) {
		HashMap<String, String> map = null;
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"FindActs", Context.MODE_PRIVATE);
		String json = sharedPreferences.getString("FindActs", "");
		Gson gson = new Gson();
		if (!TextUtils.isEmpty(json)) {
			map = gson.fromJson(json, new TypeToken<HashMap<String, String>>() {
			}.getType());

		}
		if (map != null) {
			for (String key : map.keySet()) {
				map.put(key, "1");
			}
			Editor editor = sharedPreferences.edit();
			editor.putString("FindActs", gson.toJson(map));
			editor.commit();
		}

	}

	/**
	 * 发现页快乐商城NEW图片显示，保存时间戳
	 */
	public void setTimeStamp(Context context, long timeStamp) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"TimeStamp", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putLong("timeStamp", timeStamp);
		editor.commit();
	}

	/**
	 * 发现页快乐商城NEW图片显示，获取时间戳
	 */
	public long getTimeStamp(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"TimeStamp", Context.MODE_PRIVATE);
		long timeStamp = sharedPreferences.getLong("timeStamp", -1);
		return timeStamp;
	}

	/***
	 * 第一次进入K计划详情Dialog
	 */
	public void setOneFinancialParticularsDialog(Context context,
			boolean dialogFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneFinancialParticularsDialog", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("dialogFlag", dialogFlag);
		editor.commit();
	}

	/***
	 * 第一次进入K计划详情Dialog
	 */
	public boolean getOneFinancialParticularsDialog(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneFinancialParticularsDialog", Context.MODE_PRIVATE);
		boolean dialogFlag = sharedPreferences.getBoolean("dialogFlag", true);
		return dialogFlag;
	}

	/*****
	 * 首页K计划第一次进入红点处理
	 */
	public void setOneFinancialHotDot(Context context, boolean hotDotFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneFinancialHotDot", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("hotDotFlag", hotDotFlag);
		editor.commit();
	}

	/*****
	 * 首页K计划第一次进入红点处理
	 */
	public boolean getOneFinancialHotDot(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneFinancialHotDot", Context.MODE_PRIVATE);
		boolean hotDotFlag = sharedPreferences.getBoolean("hotDotFlag", true);
		return hotDotFlag;
	}

	/*****
	 * 首页K计划第一次进入红点处理
	 */
	public void setLiveEnterTime(Context context, int time) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"LiveEnterTime", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt("time", time);
		editor.commit();
	}

	/*****
	 * 首页K计划第一次进入红点处理
	 */
	public int getLiveEnterTime(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"LiveEnterTime", Context.MODE_PRIVATE);
		int time = sharedPreferences.getInt("time", 0);
		return time;
	}

	public void setFindData(Context context, FindData data) {
		try {
			String json;
			if (data == null) {
				json = "";
			} else {
				Gson gson = new Gson();
				json = gson.toJson(data);
			}
			SharedPreferences sharedPreferences = context.getSharedPreferences(
					"find_data", Context.MODE_PRIVATE);
			Editor editor = sharedPreferences.edit();
			editor.putString("findData", json);
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public FindData getFindData(Context context) {
		try {
			SharedPreferences sharedPreferences = context.getSharedPreferences(
					"find_data", Context.MODE_PRIVATE);
			String json = sharedPreferences.getString("findData", "");
			Gson gson = new Gson();
			if (!TextUtils.isEmpty(json)) {
				FindData findData = gson.fromJson(json, FindData.class);
				return findData;
			}
			return null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/***
	 * 第一次进入K计划详情Dialog
	 */
	public void setOneCreditorIsRightsParticularsDialog(Context context,
			boolean dialogFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneCreditorIsRightsParticularsDialog", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean("dialogFlag", dialogFlag);
		editor.commit();
	}

	/***
	 * 第一次进入K计划详情Dialog
	 */
	public boolean getOneCreditorIsRightsParticularsDialog(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"OneCreditorIsRightsParticularsDialog", Context.MODE_PRIVATE);
		boolean dialogFlag = sharedPreferences.getBoolean("dialogFlag", true);
		return dialogFlag;
	}

	/***
	 * 记录非强制更新的启动次数
	 */
	public void setNumForUpdateFalse(Context context, long numFlag) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"NumForUpdateFalse", Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putLong("numFlag", numFlag);
		editor.commit();
	}

	/***
	 * 获取记录非强制更新的启动次数
	 */
	public long getNumForUpdateFalse(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"NumForUpdateFalse", Context.MODE_PRIVATE);
		long numFlag = sharedPreferences.getLong("numFlag", 0);
		return numFlag;
	}
}
